import store from '@/store'

export default {
  inserted(el, binding) {
    const { value } = binding
    const permissions = store.state.permissions

    if (value && value instanceof Array && value.length > 0) {
      const hasPermission = permissions.some(permission => {
        return value.includes(permission)
      })

      if (!hasPermission) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error('需要指定权限标识! 例如 v-permission="[\'admin\',\'editor\']"')
    }
  }
} 